'''
Created on Apr 16, 2012
TC ID: Ecom_5013
Desc: Kiem thu chuc nang tao mot nguoi dung moi
@author: lavang
'''
import unittest
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.loginPageFunc import login
from Functions.usersFunc import clickOnUsers, clickOnNewUser, createUser,\
    clickOnLinkUser, isUserCreatedSuccessfully
from HTMLTestRunner import HTMLTestRunner
import time


username=readData("username")
password=readData("password")
tm_avatar=readData("avatar")
tm_user=readData("users")
tm_password=readData("password",index=3)
tm_userType=readData("userType",index=2)
tm_language=readData("language")
tm_timeZone='(GMT +08:00) Singapore'
tm_comment='this is comment'
class Ecom_5013(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5013(self):
        print "Buoc 1 : Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 2: Click vao Users"
        clickOnUsers(self)
        
        print "Buoc 3: Click vao New User"
        clickOnNewUser(self)
        
        print "Buoc 4: Nhap thong tin va tao mot User"
        createUser(self,tm_avatar,tm_user,tm_password,tm_password,firstName=tm_user,lastName=tm_user,email='',userType=tm_userType,language=tm_language,timeZone=tm_timeZone,description='',comment=tm_comment,status='off',edit='off')
            
        print "Buoc 5: Quay lai danh sach User"
        clickOnLinkUser(self)
       
        print "Buoc 6: Kiem tra User da duoc tao"
        self.assertTrue(isUserCreatedSuccessfully(self,tm_user), "Failed")
        print "Passed: User duoc tao thanh cong"
    
    def tearDown(self):
        endCondition(self)




if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5013)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang tao User moi'
                    )
    runner.run(suite)